﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LevelButton : MonoBehaviour
{

	public Text tLevel;
	public GameObject oClear, oLock;

	int _id;

	public int id {
		get { return _id; }
		set {
			_id = value;

		}
	}

	int level;

	public void InitLevel ()
	{
		level = 16 * GW_SELECT_LEVEL.instance.levelPage + id;

		if (level < GameManager.dataSave.levelMax.GetValue ()) {
			tLevel.text = level.ToString ();
			oClear.gameObject.SetActive (true);
			oLock.gameObject.SetActive (false);
		} else if (level == GameManager.dataSave.levelMax.GetValue ()) {
			tLevel.text = level.ToString ();
			oClear.gameObject.SetActive (false);
			oLock.gameObject.SetActive (false);
		} else if (level > GameManager.dataSave.levelMax.GetValue ()) {
			tLevel.text = "";
			oClear.gameObject.SetActive (false);
			oLock.gameObject.SetActive (true);
		}
	}

	public void Click ()
	{
		#if UNITY_EDITOR
		GameManager.currentLevel = level;
		AudioManager.instance.PlaySound (AudioClipType.SE_Enter);
		WindowManager.OpenWindow (WindowName.GW_PLAY);
		#else
		if (level <= GameManager.dataSave.levelMax.GetValue ()) {
			GameManager.currentLevel = level;
			AudioManager.instance.PlaySound (AudioClipType.SE_Enter);
			WindowManager.OpenWindow (WindowName.GW_PLAY);
		}
		#endif
	}
}
